/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stateless;

import entity.Users;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author antonio
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class StatelessSessionSigninBean implements StatelessSessionSigninBeanLocal {
    
    @PersistenceContext(unitName = "SampleApplication-ejbPU")
    EntityManager manager;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    /**
     *
     * @param user
     */
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public boolean signin(Users user) {
        Users u = manager.find(Users.class, user.getUsername());
        if(u == null) {
            manager.persist(user);
            return true;
        }
        return false;
    }

}
